Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Conversation

@nazarhussain
Copy link
Contributor

Description

Fixes #5170

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have selected the correct base branch.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.
  • I ran npm run dtslint with success and extended the tests and types if necessary.
  • I ran npm run test:cov and my test cases cover all the lines and branches of the added code.
  • I ran npm run build with success.
  • I have tested the built dist/web3.min.js in a browser.
  • I have tested my code on the live network.
  • I have checked the Deploy Preview and it looks correct.
  • I have updated the CHANGELOG.md file in the root folder.

@nazarhussain nazarhussain self-assigned this Jun 29, 2022
@nazarhussain nazarhussain added the 4.x 4.0 related label Jun 29, 2022
@nazarhussain nazarhussain linked an issue Jun 29, 2022 that may be closed by this pull request
1 task
@nazarhussain nazarhussain force-pushed the nh/5170-sign-transaction branch from c450824 to 2d1f95f Compare June 29, 2022 14:43
Comment on lines 70 to 115
const signTransactionWithState = async (transaction: Transaction, privateKey: Bytes) => {
const tx = await prepareTransactionForSigning(transaction, this);

const privateKeyBytes = format({ eth: 'bytes' }, privateKey, ETH_DATA_FORMAT);

return signTransaction(tx, privateKeyBytes);
};

const privateKeyToAccountWithState = (privateKey: Buffer | string) => {
const account = privateKeyToAccount(privateKey);

return {
...account,
signTransaction: async (transaction: Transaction) =>
signTransactionWithState(transaction, account.privateKey),
};
};

const decryptWithState = async (
keystore: string,
password: string,
options?: Record<string, unknown>,
) => {
const account = await decrypt(
keystore,
password,
(options?.nonStrict as boolean) ?? true,
);

return {
...account,
signTransaction: async (transaction: Transaction) =>
signTransactionWithState(transaction, account.privateKey),
};
};

const createWithState = () => {
const account = create();

return {
...account,
signTransaction: async (transaction: Transaction) =>
signTransactionWithState(transaction, account.privateKey),
};
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions are in main web3 package for avoiding eth package dep in accounts pkg, or is there any thing else?

But I think these should be moved to accounts package as: If some one want to import signing functionality directly from accounts package the behavior will be diff.

Or if you want to keep in current way, move these functions to new file in main web3 package and document that defaults will not be filled if these functions are directly used from accounts package instead of main web3 package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned earlier in a discussion:

There are two approaches to do it.

  1. Make the signTransaction stateful accepting the context and handle rest
  2. Process state related stuff in the higher level object web3 or web3.eth and keep the signTransaction stateless.

I used second approach to have minimum changes in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, sounds good. Could you do changes as discussed in chat.

  • changelog update (under breaking changes) for these functions exported via web3 main package will have diff behavior as compared to exported in accounts package. ( filling defaults )

  • moving these state functions in diff file in same web3 package and continue using second approach

@nazarhussain nazarhussain requested a review from jdevcs June 30, 2022 15:41
@nazarhussain nazarhussain requested a review from avkos July 1, 2022 11:32
@nazarhussain nazarhussain requested a review from avkos July 1, 2022 14:08
@nazarhussain nazarhussain merged commit 5f639d8 into 4.x Jul 1, 2022
@nazarhussain nazarhussain deleted the nh/5170-sign-transaction branch July 1, 2022 14:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

4.x 4.0 related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wallet.signTransaction fail with error

4 participants